package cate.common.table.item;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteField;
import easy.java.time.DateTool;
import org.apache.commons.lang3.StringUtils;

public class ItemBaseRow extends ERow implements IBagItemTpl{
    /** 名称 */
    public String name;
    /** 类型 */
    public int type;
    /** 等级 */
    public int level;
    /** 品质 */
    public byte quality;
    /** 最大叠加数量 */
    public int pileMax;
    /** 自动使用 */
    public boolean autoUse;
    /** 出售 */
    public String sellResCode;

    public long validTime;
    private String expiredTimeStr;

    public int useItemOpenDayMin;

    public int useItemOpenDayMax;

    public double assessValue;

    @NoteField("是否一键造出")
    public boolean gmProducible;

    /* 名称备注 */
    public String nameNote;

    @NoteField("是否能进仓库")
    public boolean storeAvailable;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        this.id = xrw.getInteger("id", 0);
        this.name = xrw.getString("名称");
        this.type = xrw.getInteger("类型", 0);
        this.level = xrw.getInteger("等级", 0);
        this.quality = xrw.getByte("品质", (byte) 0);
        this.pileMax = xrw.getInteger("最大叠加数量", 1);
        this.autoUse = xrw.getBoolean("自动使用", false);
        this.sellResCode = xrw.getString("出售");
        this.validTime = xrw.getInteger("有效时间", 0);
        this.expiredTimeStr = xrw.getString("自然过期时间");
        this.useItemOpenDayMin = xrw.getInteger("道具使用开服天数下限",0);
        this.useItemOpenDayMax = xrw.getInteger("道具使用开服天数上限",0);
        this.assessValue = xrw.getDouble("估值", 1.0);
        this.gmProducible = xrw.getBoolean("是否一键造出", false);
        this.nameNote = xrw.getString("名称备注");
        this.storeAvailable = xrw.getBoolean("是否可存仓库",false);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String toName() {
        return this.nameNote;
    }

    @Override
    public boolean unique() {
        return false;
    }

    @Override
    public int getTemplateId() {
        return id;
    }

    @Override
    public long getPileMax() {
        return pileMax;
    }

    /** 自然过期时间 */
    public long expiredTime;

    @Override
    public void decode() {
        if (StringUtils.isNotBlank(expiredTimeStr)) {
            expiredTime = DateTool.instance().parseOrNull(expiredTimeStr).getTime();
        }
    }

    /**
     * 判断该物品是否会过期
     *
     * @return
     */
    public boolean willExpired() {
        return validTime > 0 || expiredTime > 0;
    }
}
